package cn.wanho.handler;

import cn.wanho.rvo.ResultEnum;
import cn.wanho.rvo.ResultVO;
import cn.wanho.util.JsonUtil;

import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 处理会话过期的类
 * @author qzw
 */
public class UserSessionInformationExpiredStrategy implements SessionInformationExpiredStrategy {
    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
        ResultVO result = ResultVO.failure(ResultEnum.USER_ACCOUNT_USE_BY_OTHERS.getResCode(), ResultEnum.USER_ACCOUNT_USE_BY_OTHERS.getResMsg());
        HttpServletResponse response = event.getResponse();
        response.setContentType("text/json;charset=utf8");
        response.getWriter().write(JsonUtil.toJson(result));
    }
}
